<template>
  <div class="box clearfix">
    <section class="section_wrap">
      <div class="title_sub prduct_bod_r">下户信息：</div>
      <intro :intro="intro" :name="borrowerName"></intro>
      <vuemap v-if="show"></vuemap>
    </section>
    <section class="section_wrap">
      <div class="title_sub infro_bod_l">信息录入：</div>
      <Information
        ref="info"
        :info="info"
        :showInput="showInput"
        :id="id"
        :intro="intro"
      ></Information>
    </section>
<!--    <section class="section_wrap">-->
<!--      <div class="title_sub upload_bod_l">下户地址</div>-->
<!--      &lt;!&ndash; 获取地图下户地址！ &ndash;&gt;-->
<!--      &lt;!&ndash; address地图金纬度！ &ndash;&gt;-->
<!--      <MapMaker :address0="address" v-if="address.length"></MapMaker>-->
<!--      &lt;!&ndash; <div id="container" class="mymap"></div> &ndash;&gt;-->
<!--    </section>-->
    <section class="section_wrap">
      <div class="title_sub upload_bod_l">附件管理：(所有照片尽量横着照)</div>
      <upload  
        :intro.sync="intro"
        :id="id"
        :imgList="imgList"
        :sStatus="sStatus"
        :showAss="true"
        :isSurvey="isSurvey"
      ></upload>
    </section>
    <section class="section_wrap">
      <el-popconfirm
        title="确认通过此订单？"
        @onConfirm="adopt"
        v-if="trial && rStatus && aStatus"
      >
        <el-button slot="reference" type="primary" size="small" class="btn"
          >审核通过</el-button
        >
      </el-popconfirm>
      <el-popconfirm
        title="确认驳回此订单？"
        @onConfirm="reject"
        v-if="trial && rStatus && aStatus"
      >
        <el-button slot="reference" type="danger" size="small" class="btn"
          >驳回</el-button
        >
      </el-popconfirm>
      <el-button
        @click="addData"
        v-if="isSurvey && sStatus"
        type="primary"
        size="small"
        class="btn"
        >提交</el-button
      >
      <!-- <button @click="inlink"></button> -->
    </section>
  </div>
</template>
<script>
import Information from "../../components/survey/Information";
import upload from "../../components/survey/upload";
import intro from "../../components/survey/Intro";
// import MapMaker from "../../components/map/MapMaker";
import { checkPermiss } from "../../assets/js/utlis";
import {
  getSurResult,
  addSurData,
  updateSurData,
  auditSurvey,
  updateStatus
} from "../../../src/assets/js/api";
export default {
  components: {
    Information,
    upload,
    // MapMaker,
    intro,
  },
  data() {
    return {
      // address地图经纬度！
      address: [],
      show: false,
      borrowerName: "",
      id: 0,
      imgList: [],
      info: {},
      intro: {},
      isNew: true,
      showInput: true,
      //提交状态
      sStatus: false,
      //驳回状态
      rStatus: false,
      //审核通过
      aStatus: false,
      //是否下户人员
      isSurvey: false,
      golbalPermissions: [],
      //   是否是审件专员!
      trial: false,
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.borrowerName = this.$route.query.borrowerName;
    // this.loadmap();
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    //获取订单详情！
    this.getSurResult();
  },
  computed: {
    //提交按钮
    showAudit: function () {
      return checkPermiss("business:survey:audit", this.golbalPermissions);
    },
    //驳回
    showReject: function () {
      return checkPermiss("business:survey:reject", this.golbalPermissions);
    },
    //提交/更新按钮
    showAdd: function () {
      return checkPermiss("business:survey:addData", this.golbalPermissions);
    },
  },
  methods: {
    // loadmap() {
    //   var map = new VueAMap.Map("container", {
    //     //new一个对象，传入初始化设置
    //     zoom: 10,
    //   });
    //   // this.testevent();
    //   // this.test2();

    // },

    //通过
   
    adopt() {
      let obj = {
        id: this.id,
        state: 1,
      };
      this.auditSurvey(obj);
    },
    //驳回
    reject() {
      let obj = {
        id: this.id,
        state: 0,
        note: "资料不齐全",
      };
      this.auditSurvey(obj);
    },
    //审核通过驳回
    auditSurvey(obj) {
      auditSurvey(obj).then((res) => {
        this.$message.success(res.message);
        this.$router.push({
          path: "/Index/ExistSurvey",
        });
      });
    },
    //获取下户详情
    getSurResult() {
      getSurResult(this.id).then((res) => {
        this.imgList = res.data.mapSurveyAccessory || [];
        this.info = res.data.tbSurveyDataVo; //信息录入数据!
        this.intro = res.data.tbSurvey;
        this.isNew = !res.data.hasData;
        //下户坐标！
        this.address[1] = JSON.parse(this.intro.la);
        this.address[0] = JSON.parse(this.intro.lo);
        //提交状态
        this.sStatus = res.data.submitStatus;
        //驳回状态
        this.rStatus = res.data.rejectStatus;
        //审核状态
        this.aStatus = res.data.approveStatus;
        //是否是下户人员!
        this.isSurvey = res.data.hasSurvey;
        // 是否是审件专员!
        this.trial = res.data.hasApprove;
      });
    },
    //添加数据
    addData() {


      if( this.intro.state==5){

        updateStatus({
          sid:this.intro.id,
          status:4,
        }).then(res=>{
          this.$message.success("提交成功");
          this.$router.push({
            path: "/Index/ExistSurvey",
          });
        })
      }else {
        // let data = this.$refs.info.form;
        let data = this.$refs.info.tbSurveyData;
        // data.sid = this.id;
        // let tbSurveyData = {
        //   tbSurveyData: data,
        // };
        addSurData(data).then(() => {
          this.$message.success("添加信息成功");
          this.$router.push({
            path: "/Index/ExistSurvey",
          });
        });
      }

    },
    //更新数据
    updateData() {
      let data = this.$refs.info.form;
      data.sid = this.id;
      let tbSurveyData = {
        tbSurveyData: data,
      };
      updateSurData(tbSurveyData).then(() => {
        this.$message.success("更新成功");
        this.$router.push({
          path: "/Index/ExistSurvey",
        });
      });
    },
  },
};
</script>
<style lang="less" scoped>
.btn {
  margin: 0 10px;
}
#container {
  width: 300px;
  height: 180px;
}
</style>
